package cn.com.headfree.point.dao.impl;

import cn.com.headfree.entity.TEmpBaseInfo;
import cn.com.headfree.entity.TPartRank;
import cn.com.headfree.entity.TPersonYearPoint;
import cn.com.headfree.entity.TRuleElementInfo;
import cn.com.headfree.point.dao.ISalaryUserDataInfoDao;
import cn.com.headfree.vo.*;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * @Description: TODO
 * @Author wcSun
 * @Date 2021/6/22
 **/
@Repository("salaryUserDataInfoDao")
public class SalaryUserDataInfoDaoImpl extends BaseDaoImpl<TPersonYearPoint> implements ISalaryUserDataInfoDao {

    Calendar date = Calendar.getInstance();
    int currentYear = Integer.valueOf(date.get(Calendar.YEAR));
    int lastYear = currentYear - 1;
    String startDate = lastYear + "-01-01";
    String endDate = lastYear + "-12-31";

    //前年
    int beforeYear = lastYear - 1;
    String beforestartDate = beforeYear + "-01-01";
    String beforendDate = beforeYear + "-12-31";

    @Override
    public void updateProTecInfoSalaryIdByErpNo(String erpNo, String salaryId, int year ){
        String sql = "update t_pro_tec_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.post_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateSkillLevelInfoSalaryIdByErpNo(String erpNo,String salaryId, int year){
        String sql = "update t_skill_level_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.post_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }


    @Override
    public void updateEducateInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_educate_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.acqu_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateExpertTitleInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_expert_title_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.post_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateAcadeAchiveInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_part_rank r RIGHT JOIN t_acade_achive_info t on t.id = r.item_id set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" r.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where r.item_type='12' and t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.pub_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updatePatentInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_part_rank r RIGHT JOIN t_patent_info t on t.id = r.item_id set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" r.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where r.item_type='14' and t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.decl_date BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateTecManInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_part_rank r RIGHT JOIN t_tec_man_innov t on t.id = r.item_id set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" r.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where r.item_type='16' and t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.award_date BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateTecInnovInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_part_rank r RIGHT JOIN t_tec_innov_info t on t.id = r.item_id set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" r.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where r.item_type='15' and t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.award_date BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateContestInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_contest_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.award_date BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateHonnorInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_honor_info t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.acqu_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateTecStandardInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_part_rank r RIGHT JOIN t_tec_standard_info t on t.id = r.item_id set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" r.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where r.item_type='21' and t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.post_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }

    @Override
    public void updateEmployeeMobilityInfoSalaryIdByErpNo(String erpNo, String salaryId, int year){
        String sql = "update t_employee_mobility t set ";
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" t.salary_id = #{salary_id,jdbcType=VARCHAR} ");
        sqlBuilder.append(" where t.is_valid='0' and t.del_sign = '0'  ");
        Map<String, Object> params = new HashMap<String, Object>();
        sqlBuilder.append(" and t.erp_no=#{erp_no,jdbcType=VARCHAR}");
        sqlBuilder.append(" and t.acqu_time BETWEEN #{start_time,jdbcType=VARCHAR} and #{end_time,jdbcType=VARCHAR}");
        params.put("salary_id",salaryId);
        params.put("erp_no",erpNo);
        params.put("start_time",year + "-01-01");
        params.put("end_time",year + "-12-31");
        this.executeSql(sqlBuilder.toString(), params);
    }
}
